﻿
using MediatR;

namespace Catalog.API.Products.GetProductById
{
    //public record GetProductByIdRequest(Guid Id);
    public record GetProductByIdResponse(Product Product);
    public class GetProductByIdEndpoint : ICarterModule
    {
        public void AddRoutes(IEndpointRouteBuilder app)
        {
            //路由参数的写法,路由参数会把参数放到地址中，如：http://localhost:5000/product/12345678-1234-123456789012
            app.MapGet("/product/{id}", async(Guid id,ISender sender) =>
            {
               var result= await sender.Send(new GetProductByIdQuery(id));
               var response=result.Adapt<GetProductByIdResponse>();
                return Results.Ok(response);
            }).WithName("GetProductById")
            .Produces<GetProductByIdResponse>(StatusCodes.Status200OK)
            .ProducesProblem(StatusCodes.Status400BadRequest)
            .WithSummary("Get Product By Id")
            .WithDescription("Get Product By Id"); ;
        }
    }
}
